import java.lang.reflect.*;

interface Moveable {
    void move();
    void stop();
}

class Tank implements Moveable {
    @Override
    public void move() {
        System.out.println("Tank Moving...!");
    }
    @Override
    public void stop() {
        System.out.println("Tank Stop...!");
    }
}

class Proxy {
    Object o;
    Method [] methods;

    public Proxy(Object o) {
        this.o = o;
        methods = o.getClass().getMethods();
    }

    public Object invoke(String name, Object ... args) throws Exception {
        Object r = null;
        Method m = getMethod(name, args);
        if (m == null)
            throw new Exception("找不到方法!");

        System.out.println("move Before...");
        r = m.invoke(o, args);
        System.out.println("move After...");

        return r;
    }

    public Method getMethod(String name, Object ... args) {
        for (Method m : methods) {
            if (name.equals(m.getName())) {
                return m;
            }
        }
        return null;
    }
}

public class DynamicProxyTest {
    static public void main(String [] args) throws Exception {
        Tank tank = new Tank();
        tank.move();

        System.out.printf("==============\n");

        Proxy p = new Proxy(tank);
        p.invoke("move");
        p.invoke("stop");
        p.invoke("start");
    }
}
